package com.zzxz.practicaltrainingsys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzxz.practicaltrainingsys.entity.Log;
import com.zzxz.practicaltrainingsys.mapper.DailynewsMapper;
import com.zzxz.practicaltrainingsys.mapper.LogMapper;
import com.zzxz.practicaltrainingsys.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;


    @Override
    public int insertLog(Log log) {
        return logMapper.insertLog(log);
    }

    @Override
    public List<Log> getLogList() {
        return logMapper.getLogList();
    }

    @Override
    public PageInfo<Log> getLogByPage(Integer pageNum, Integer pageSize) {
        // 参数校验
        if (pageNum == null || pageNum <= 0) pageNum = 1;
        if (pageSize == null || pageSize <= 0) pageSize = 10;

        // 启动分页（确保在执行查询前调用）
        PageHelper.startPage(pageNum, pageSize);

        try {
            // 执行查询
            List<Log> logList = logMapper.getLogList();
            // 封装分页信息
            return new PageInfo<>(logList);
        } finally {
            // 清理分页状态
            PageHelper.clearPage();
        }
    }
}
